home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / gfx / misc / gnuplot-src.lha / gnuplot-3.7.1src / gnuplot-3.7.1.lha / gnuplot-3.7.1 / docs / doc2gih.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-19  |  3.8 KB  |  149 lines

  1. /*
  2.  * $Id: d V2b)
  3. char 998/10/19 13:17:28 lhecking Exp $
  4.  *
  5.  */
  6.  
  7. /* GNUPLOT - doc2gih.c */
  8.  
  9. /*[
  10.  * Copyright 1986 - 1993, 1998   Thomas Williams, Colin Kelley
  11.  *
  12.  * Permission to use, copy, and distribute this software and its
  13.  * documentation for any purpose with or without fee is hereby granted,
  14.  * provided that the above copyright notice appear in all copies and
  15.  * that both that copyright notice and this permission notice appear
  16.  * in supporting documentation.
  17.  *
  18.  * Permission to modify the software is granted, but not the right to
  19.  * distribute the complete modified source code.  Modifications are to
  20.  * be distributed as patches to the released version.  Permission to
  21.  * distribute binaries produced by compiling modified sources is granted,
  22.  * provided you
  23.  *   1. distribute the corresponding source modifications from the
  24.  *    released version in the form of a patch file along with the binaries,
  25.  *   2. add special version identification to distinguish your version
  26.  *    in addition to the base release version number,
  27.  *   3. provide your name and address as the primary contact for the
  28.  *    support of your modified version, and
  29.  *   4. retain our contact information in regard to use of the base
  30.  *    software.
  31.  * Permission to distribute the released version of the source code along
  32.  * with corresponding source modifications in the form of a patch file is
  33.  * granted with same provisions 2 through 4 for binary distributions.
  34.  *
  35.  * This software is provided "as is" without express or implied warranty
  36.  * to the extent permitted by applicable law.
  37. ]*/
  38.  
  39. /*
  40.  * doc2gih.c  -- program to convert Gnuplot .DOC format to gnuplot
  41.  * interactive help (.GIH) format.
  42.  *
  43.  * This involves stripping all lines with a leading digit or
  44.  * a leading @, #, or %.
  45.  * Modified by Russell Lang from hlp2ms.c by Thomas Williams 
  46.  *
  47.  * usage:  doc2gih [file.doc [file.gih]]
  48.  *
  49.  * Original version by David Kotz used the following one line script!
  50.  * sed '/^[0-9@#%]/d' file.doc > file.gih
  51.  */
  52.  
  53. #ifdef HAVE_CONFIG_H
  54. # include "config.h"
  55. #endif
  56.  
  57. #include "ansichek.h"
  58. #include "stdfn.h"
  59. #include "doc2x.h"
  60.  
  61. void convert __PROTO((FILE *, FILE *));
  62. void process_line __PROTO((char *, FILE *));
  63.  
  64. int main(argc, argv)
  65. int argc;
  66. char **argv;
  67. {
  68.     FILE *infile;
  69.     FILE *outfile;
  70.  
  71.     infile = stdin;
  72.     outfile = stdout;
  73.  
  74.     if (argc > 3) {
  75.     fprintf(stderr, "Usage: %s [infile [outfile]]\n", argv[0]);
  76.     exit(EXIT_FAILURE);
  77.     }
  78.     if (argc >= 2) {
  79.     if ((infile = fopen(argv[1], "r")) == (FILE *) NULL) {
  80.         fprintf(stderr, "%s: Can't open %s for reading\n",
  81.             argv[0], argv[1]);
  82.         exit(EXIT_FAILURE);
  83.     }
  84.     }
  85.     if (argc == 3) {
  86.     if ((outfile = fopen(argv[2], "w")) == (FILE *) NULL) {
  87.         fprintf(stderr, "%s: Can't open %s for writing\n",
  88.             argv[0], argv[2]);
  89.         exit(EXIT_FAILURE);
  90.     }
  91.     }
  92.  
  93.     convert(infile, outfile);
  94.  
  95.     exit(EXIT_SUCCESS);
  96. }
  97.  
  98.  
  99. void convert (inf, outf)
  100. FILE *inf, *outf;
  101. {
  102.     static char line[MAX_LINE_LEN+1];
  103.  
  104.     while (get_line(line, sizeof(line), inf))
  105.         process_line(line, outf);
  106. }
  107.  
  108.  
  109. void process_line(line, b)
  110. char *line;
  111. FILE *b;
  112. {
  113.     static int line_count = 0;
  114.  
  115.     line_count++;
  116.  
  117.     switch (line[0]) {        /* control character */
  118.     case '?':{            /* interactive help entry */
  119.         (void) fputs(line, b);
  120.         break;
  121.     }
  122.     case '@':{            /* start/end table */
  123.         break;        /* ignore */
  124.     }
  125.     case '#':{            /* latex table entry */
  126.         break;        /* ignore */
  127.     }
  128.     case '%':{            /* troff table entry */
  129.         break;        /* ignore */
  130.     }
  131.     case '^':{            /* html entry */
  132.         break;        /* ignore */
  133.     }
  134.     case '\n':            /* empty text line */
  135.     case ' ':{            /* normal text line */
  136.         (void) fputs(line, b);
  137.         break;
  138.     }
  139.     default:{
  140.         if (isdigit((int)line[0])) {    /* start of section */
  141.         /* ignore */
  142.         } else
  143.         fprintf(stderr, "unknown control code '%c' in column 1, line %d\n",
  144.             line[0], line_count);
  145.         break;
  146.     }
  147.     }
  148. }
  149.